package com.example.demo.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * <p>Title: UUIDUtils.java</p>  
 * <p>Description: UUID工具类</p>  
 * @author tymac
 * @date 2017年12月22日
 */
public class UUIDUtils {
	
	public static SimpleDateFormat sdf = new SimpleDateFormat("HHmmss");
	/**
	 * 得到一个随机的32位的UUID值-hhmmss_uuid(25位)
	 * @return
	 */
	public static String getUUIDValue() {
		//随即得到一个uuid的String值
		String uuid = UUID.randomUUID().toString().replaceAll("\\-", "");
		//当前时间时分秒+_+uuid截取25位
		  Date d = new Date();    
	      String dateNowStr = sdf.format(d);  
		  uuid=dateNowStr+"_"+uuid.substring(0,uuid.length()-7);
		return uuid;
	}
	
	/**
	 * 得到一个随机的32位的值
	 * @return
	 */
	 public static  String setRand() { 
	        String rad = "0123456789"; 
	        StringBuffer result = new StringBuffer(); 
	        Random rand = new Random(); 
	        int length = 32; 
	        for (int i = 0; i < length; i++) { 
	            int randNum = rand.nextInt(10); 
	            result.append(rad.substring(randNum, randNum + 1)); 
	        } 
	        return result.toString(); 
	    } 

	public static void main(String[] args) {
		String s="存放文件正常路径：C:/esb_tmp_file/chac//PolicyFeeCount/20131012/response/20131012140821453.xml";
		System.out.println(s.length());
		System.out.println(getUUIDValue());
	}
}
